/**
 * 
 */
package com.planner.core.service.core.search;

import java.util.LinkedList;
import java.util.List;

import org.springframework.beans.factory.annotation.Required;

import com.planner.core.algorithm.dijkstra.engine.DijkstraAlgorithm;
import com.planner.core.algorithm.dijkstra.model.Graph;
import com.planner.core.service.core.algorithm.AlgorithmService;
import com.planner.core.service.core.stop.StopService;
import com.planner.core.vo.GraphNode;

/**
 * @author Sangharsh
 *
 */
public class MetroSearchServiceImpl implements SearchService {

	private AlgorithmService algorithmService;
	private StopService stopService;
	/* (non-Javadoc)
	 * @see com.planner.core.service.core.search.SearchService#getPath(int, int)
	 */
	public List<GraphNode> getPath(int start, int destination) {
		GraphNode startNode = stopService.getNode(start);
		GraphNode destinationNode = stopService.getNode(destination);
		Graph graph = new Graph(algorithmService.getNodes(), algorithmService.getEdges());
		DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(graph);
		dijkstra.execute(startNode);
		LinkedList<GraphNode> path = dijkstra.getPath(destinationNode);
		return path;
	}
	
	/**
	 * @param stopService the stopService to set
	 */
	@Required
	public void setStopService(StopService stopService) {
		this.stopService = stopService;
	}

	/**
	 * @param algorithmService the algorithmService to set
	 */
	@Required
	public void setAlgorithmService(AlgorithmService algorithmService) {
		this.algorithmService = algorithmService;
	}

}
